package com.example;

import java.util.Properties;

import javax.sql.DataSource;

import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.datasource.pooled.PooledDataSourceFactory;

public class UserDataSourceFactory implements DataSourceFactory {
    // 属性集合
    private Properties properties;

    // 从外部传入属性集合
    @Override
    public void setProperties(Properties props) {
        properties = props;
    }

    // 获得数据源
    @Override
    public DataSource getDataSource() {
        // 实例化数据源池对象
        PooledDataSourceFactory pooledDataSourceFactory = new PooledDataSourceFactory();
        // 传入属性集合
        pooledDataSourceFactory.setProperties(properties);
        // 返回数据源
        return pooledDataSourceFactory.getDataSource();
    }
}
